package com.fanben100.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

class MyCellRenderer extends JLabel implements ListCellRenderer {
	public MyCellRenderer() {
		setOpaque(true);
	}

	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		Font cellFont = new Font("宋体", Font.BOLD, 16);
		setFont(cellFont);
		setText(value.toString());
		setHorizontalAlignment(JLabel.CENTER); // /////// <------------
		setBackground(isSelected ? Color.red : Color.white);
		setForeground(isSelected ? Color.white : Color.black);
		return this;
	}
}
